#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/9/21 12:42
# @Author  : AshJo
# @Desc    : 继承
# @Filename: Inheritance.py
# @Version : v1.0
"""


# 继承 - 需要解决代码的重复性

# 父类
class Animal:
    def __init__(self, name, food):
        self.name = name
        self.food = food
        self.hp = 100
        self.int = 250

    def eat(self):
        print('%s 正在吃 %s' % (self.name, self.food))

    def drink(self):
        print('%s 正在喝...' % self.name)

    def sleep(self):
        print('%s 正在睡觉...' % self.name)


# 子类
class Cat(Animal):
    def __init__(self, name, food, eye_color):
        Animal.__init__(self, name, food)
        self.eye_color = eye_color

    def eat(self):
        self.int += 100
        Animal.eat(self)

    def climbing(self):
        print('%s 正在爬树...' % self.name)


class Dog(Animal):
    def __init__(self, name, food, size):
        Animal.__init__(self, name, food)
        self.size = size  # 派生属性

    def eat(self):
        self.hp += 100
        Animal.eat(self)

    def guarding(self):
        print('%s 正在守家...' % self.name)


cat = Cat('年糕', '猫粮', '蓝色')
cat.eat()
cat.drink()
cat.sleep()
cat.climbing()

dog = Dog('小白', '狗粮', '小型狗')
dog.eat()
dog.drink()
dog.sleep()
dog.guarding()

print(dog.__dict__)
print(cat.__dict__)
